package controller.transform;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class TransformPanel extends JPanel {

	public static final int ROTATION_MODE=0;
	public static final int ALIGN_TUBES_MODE=1;
	public static final int ALIGN_TUBE_XY_MODE=2;
	public static final int ALIGN_TUBE_XZ_MODE=3;
	public static final int ALIGN_TUBE_YZ_MODE=4;
	public static final int MAKE_TRIANGLE=5;
	public static final int MAKE_SQUARE=6;
	public static final int MAKE_PENTAGON=7;
	public static final int MAKE_HEXAGON=8;
	public static final int MAKE_7=9;
	
	private static final String ROTATION_MODE_TEXT = "Rotation mode";
	private static final String ALIGN_TUBES_TEXT = "Align tubes";
	private static final String ALIGN_TUBE_XY_TEXT = "Align tube with XY";
	private static final String ALIGN_TUBE_XZ_TEXT = "Align tube with XZ";
	private static final String ALIGN_TUBE_YZ_TEXT = "Align tube with YZ";
	
	private static final String MAKE_TRIANGLE_TEXT = "Form triangle angles";
	private static final String MAKE_SQUARE_TEXT = "Form 90-degree angles";
	private static final String MAKE_PENTAGON_TEXT = "Form pentagon angles";
	private static final String MAKE_HEXAGON_TEXT = "Form hexagon angles";
	private static final String MAKE_N_TEXT = "Form angle n=";
	
	private JComboBox combo;
	
	private int mode = ROTATION_MODE;
	private final ModeListener modeListener;
	
	public TransformPanel(ModeListener listener) {
		this.setLayout(new BorderLayout());
		this.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
		
		this.setOpaque(false);
		
		Box box = Box.createHorizontalBox();
		this.combo = new JComboBox(new String[] {
			ROTATION_MODE_TEXT,
			ALIGN_TUBES_TEXT,
			ALIGN_TUBE_XY_TEXT,
			ALIGN_TUBE_XZ_TEXT,
			ALIGN_TUBE_YZ_TEXT,
			MAKE_TRIANGLE_TEXT,
			MAKE_SQUARE_TEXT,
			MAKE_PENTAGON_TEXT,
			MAKE_HEXAGON_TEXT,
			MAKE_N_TEXT + "7",
			MAKE_N_TEXT + "8",
			MAKE_N_TEXT + "9",
			MAKE_N_TEXT + "10",
			MAKE_N_TEXT + "11",
			MAKE_N_TEXT + "12"
		});
		JLabel label = new JLabel("Transformation mode: ");
		label.setForeground(Color.white);
		box.add(label);
		box.add(combo);
		box.add(Box.createHorizontalGlue());
		this.add(box, BorderLayout.CENTER);
		combo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				newModeSelected(combo.getSelectedIndex());
			}
		});
		this.modeListener = listener;
	}
	
	public int getMode() {
		return mode;
	}
	
	private void newModeSelected(int mode) {
		this.mode = mode;
		modeListener.newMode(mode);
	}
	
}
